import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/index'),
        hidden: true
    },

    {
        path: '/404',
        component: () =>
            import ('@/views/404'),
        hidden: true
    },

    {
        path: '/',
        component: Layout,
        redirect: '/home',
        children: [{
            path: 'home',
            name: '首页',
            component: () =>
                import ('@/views/service/dashboard/index'),
            meta: { title: '首页', icon: 'bank-fill' }
        }]
    },




    {
        path: '/group',
        component: Layout,
        redirect: '/group/unit',
        name: '集团管理',
        meta: { title: '集团管理', icon: 'key_units' },
        children: [{
                path: 'unit',
                name: '单位',
                component: () =>
                    import ('@/views/service/unit/index'),
                meta: { title: '单位', icon: 'community-line' }
            },
            {
                path: 'department',
                name: '部门',
                component: () =>
                    import ('@/views/service/part/index'),
                meta: { title: '部门', icon: 'tree' }
            },
            {
                path: 'managers',
                name: '管理员',
                component: () =>
                    import ('@/views/service/managers/index'),
                meta: { title: '管理员', icon: 'team' }
            }
        ]
    },



    {
        path: '/form',
        component: Layout,
        redirect: '/form/flow',
        name: '表单中心',
        meta: { title: '表单中心', icon: 'form_favor_light' },
        children: [{
                path: 'unflow',
                name: '无流程表单',
                component: () =>
                    import ('@/views/service/unflowForm/index'),
                meta: { title: '无流程表单', icon: 'file-text' }
            },
            {
                path: 'flow',
                name: '流程表单',
                component: () =>
                    import ('@/views/service/form/index'),
                meta: { title: '流程表单', icon: 'solution' }
            }
        ]
    },


    {
        path: '/banner',
        component: Layout,
        children: [{
            path: '',
            name: '轮播图管理',
            component: () =>
                import ('@/views/service/banner/index'),
            meta: { title: '轮播图管理', icon: 'bannerpeizhi' }
        }]
    },


    {
        path: '/profile',
        component: Layout,
        hidden: true,
        children: [{
            path: '',
            name: '个人中心',
            component: () =>
                import ('@/views/service/profile/index'),
            meta: { title: '个人中心', icon: 'user' }
        }]
    },


    {
        path: '/user',
        component: Layout,
        children: [{
            path: '',
            name: '用户管理',
            component: () =>
                import ('@/views/service/users/index'),
            meta: { title: '用户管理', icon: 'user' }
        }]
    },


    {
        path: '/shop',
        component: Layout,
        redirect: '/shop/manager',
        name: '产品管理',
        meta: { title: '产品管理', icon: 'shop' },
        children: [{
                path: 'manager',
                name: '商品管理',
                component: () =>
                    import ('@/views/service/shop/index'),
                meta: { title: '商品管理', icon: 'shopping' }
            },
            {
                path: 'sort',
                name: '商品类别',
                component: () =>
                    import ('@/views/service/shopsort/index'),
                meta: { title: '商品类别', icon: 'Category' }
            },
            {
                path: 'map',
                name: '物流管理',
                component: () =>
                    import ('@/views/service/vueamap/index'),
                meta: { title: '物流管理', icon: 'ditu-dibiao' }
            }
        ]
    },



    {
        path: '/credit',
        component: Layout,
        children: [{
            path: '',
            name: '信誉中心',
            component: () =>
                import ('@/views/service/Credit/index'),
            meta: { title: '信誉中心', icon: 'credit' }
        }]
    },


    {
        path: '/data',
        component: Layout,
        children: [{
            path: '',
            name: '数据分析',
            component: () =>
                import ('@/views/service/data/index'),
            meta: { title: '数据分析', icon: 'linechart' }
        }]
    },
    {
        path: '/vedio',
        component: Layout,
        children: [{
            path: '',
            name: 'AI',
            component: () =>
                import ('@/views/service/vedio/vedio'),
            meta: { title: 'AI', icon: 'rengongzhinengdanao' }
        }]
    },






    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router